unit Unit41; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Unit36,
  Grids, Unit37, LR_DSet, LR_Class, LR_PGrid, Unit44;

type

  { TForm41 }

  TForm41 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    frReport1: TfrReport;
    filas: TfrUserDataset;
    columnas: TfrUserDataset;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    StringGrid1: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure columnasCheckEOF(Sender: TObject; var Eof: Boolean);
    procedure columnasFirst(Sender: TObject);
    procedure columnasNext(Sender: TObject);
    procedure filasCheckEOF(Sender: TObject; var Eof: Boolean);
    procedure filasFirst(Sender: TObject);
    procedure filasNext(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure frReport1GetValue(const ParName: String; var ParValue: Variant);
  private
    FRow: Integer;
    FCol: Integer;
  public

  end; 

var
  Form41: TForm41; 

implementation

{ TForm41 }

procedure TForm41.FormShow(Sender: TObject);
begin
  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';
  Edit4.Text := '';
  Edit5.Text := '';
  Edit6.Text := '0';
  Edit7.Text := '';
  
  ComboBox1.Text := 'Lista 1';
  
  StringGrid1.RowCount := 1;
end;

procedure TForm41.frReport1GetValue(const ParName: String; var ParValue: Variant
  );
begin
  if ParName = 'prs_nombre_cliente' then
    ParValue := Edit1.Text;
    
  if ParName = 'prs_direccion' then
    ParValue := Edit2.Text;

  if ParName = 'prs_cantidad' then
    ParValue := StringGrid1.Cells[1, FRow];
    
  if ParName = 'prs_producto' then
    ParValue := StringGrid1.Cells[2, FRow];
    
  if ParName = 'prs_punitario' then
    ParValue := StringGrid1.Cells[3, FRow];
    
  if ParName = 'prs_ptotal' then
    ParValue := StringGrid1.Cells[4,FRow];
    
  if ParName = 'prs_total' then
    ParValue := Edit6.Text;
    
  if ParName = 'prs_fecha_hasta' then
    ParValue := Edit7.Text;
end;

procedure TForm41.Button1Click(Sender: TObject);
begin
  Form36.ShowModal;
  Edit1.Text := Form36.nombre;
  Edit2.Text := Form36.direccion;
  Button6.SetFocus;
end;

procedure TForm41.Button2Click(Sender: TObject);
begin
  Form37.ShowModal;
  Edit3.Text := Form37.nombre_producto;

  if ComboBox1.Text = 'Lista 1' then
    Edit4.Text := FormatFloat('###0.00', StrToFloat(Form37.precio1))
  else
  if ComboBox1.Text = 'Lista 2' then
    Edit4.Text := FormatFloat('###0.00', StrToFloat(Form37.precio2))
  else
  if ComboBox1.Text = 'Lista 3' then
    Edit4.Text := FormatFloat('###0.00', StrToFloat(Form37.precio3))
  else
  if ComboBox1.Text = 'Lista 4' then
    Edit4.Text := FormatFloat('###0.00', StrToFloat(Form37.precio4));

  Edit5.Text := '1';
  Edit5.SetFocus;
end;

procedure TForm41.Button3Click(Sender: TObject);
begin
  StringGrid1.RowCount := StringGrid1.RowCount +1;
  StringGrid1.Cells[1, StringGrid1.RowCount - 1] := Edit5.Text;
  StringGrid1.Cells[2, StringGrid1.RowCount - 1] := Edit3.Text;
  StringGrid1.Cells[3, StringGrid1.RowCount - 1] := Edit4.Text;
  StringGrid1.Cells[4, StringGrid1.RowCount - 1] :=
    FormatFloat('###0.00', StrToFloat(Edit5.Text) * StrToFloat(Edit4.Text));

  Edit6.Text := FormatFloat('###0.00', StrToFloat(Edit6.Text)
    + StrToFloat(StringGrid1.Cells[4, StringGrid1.RowCount - 1]));
    
  Edit3.Text := '';
  Edit4.Text := '';
  Edit5.Text := '';
  
  Edit3.SetFocus;
end;

procedure TForm41.Button4Click(Sender: TObject);
begin
  Edit6.Text := FormatFloat('###0.00', StrToFloat(Edit6.Text)
    - StrToFloat(StringGrid1.Cells[4, StringGrid1.RowCount - 1]));
    
  StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;

procedure TForm41.Button5Click(Sender: TObject);
begin
  frReport1.LoadFromFile('presupuesto.lrf');
  frReport1.ShowReport;
  
  Close;
end;

procedure TForm41.Button6Click(Sender: TObject);
begin
  Form44.ShowModal;
  Edit7.Text := Form44.fecha_hasta;
  Edit3.SetFocus;
end;

procedure TForm41.columnasCheckEOF(Sender: TObject; var Eof: Boolean);
begin
  Eof := FCol > 4;
end;

procedure TForm41.columnasFirst(Sender: TObject);
begin
  FCol := 1;
end;

procedure TForm41.columnasNext(Sender: TObject);
begin
  Inc(FCol);
end;

procedure TForm41.filasCheckEOF(Sender: TObject; var Eof: Boolean);
begin
  Eof := FRow > StringGrid1.RowCount - 1;
end;

procedure TForm41.filasFirst(Sender: TObject);
begin
  FRow := 1;
end;

procedure TForm41.filasNext(Sender: TObject);
begin
 Inc(FRow);
end;

initialization
  {$I unit41.lrs}

end.

